<template>
  <div class="app-container">
    <loading v-show="loading"></loading>
    <el-card class="box-card searchFormStyle" style="margin-bottom:1%;">
      <div slot="header" class="clearfix">
        <span>考核周期操作</span>
      </div>
      <div class="text item">
        <el-form ref="searchData" :model="searchData" label-width="130px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="考核周期名称">
                <el-input v-model="searchData.assessmenYear"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item>
                <el-button type="primary" 
                v-if="permissionHandle('partyMemberCircle:openDialog')"
                icon="el-icon-plus" 
                @click="openDialog">新 增</el-button>
                <el-button type="primary" 
                v-if="permissionHandle('partyMemberCircle:getList')"
                icon="el-icon-search" 
                @click="getList">查 询</el-button>
                <el-button type="primary" 
                v-if="permissionHandle('partyMemberCircle:getList')"
                icon="el-icon-refresh" 
                @click="resetSearch">重 置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>考核周期列表</span>
        </div>
        <el-table
        :data="tableData"
        border
        ref="tableData"
        style="width: 100%;margin-bottom:1%;"
        >
        <el-table-column
          label="考核周期名称"
        >
          <template slot-scope="scope">
              {{ scope.row.assessmenYear }}
          </template>
        </el-table-column>
        <el-table-column
          label="考核开始时间"
        >
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.assessmenBeginTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="考核结束时间"
        >
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.assessmenEndTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="考核周期状态"
        >
          <template slot-scope="scope">
              {{ scope.row.releaseState }}
          </template>
        </el-table-column>
        <el-table-column
          label="创建日期"
          width="180"
        >
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="360px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              icon="el-icon-document"
              v-if="permissionHandle('partyMemberCircle:handleDetails')"
              @click="handleDetail(scope.$index, scope.row)">详情</el-button>
            <el-button
              size="mini"
              icon="el-icon-printer"
              v-if="scope.row.releaseState ==='待发布' && permissionHandle('partyMemberCircle:release')"
              @click="pushData(scope.$index, scope.row)">发布</el-button>
            <el-button
              size="mini"
              icon="el-icon-edit-outline"
              v-if="scope.row.releaseState ==='待发布'"
              @click="handleEdit(scope.$index, scope.row) && permissionHandle('partyMemberCircle:handleEdit')">修改</el-button>
            <el-button
              size="mini"
              icon="el-icon-delete"
              type="danger"
              v-if="scope.row.releaseState ==='待发布'"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="子考核" width="100px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              icon="el-icon-edit-outline"
              v-if="scope.row.releaseState ==='待发布' && permissionHandle('partyMemberCircle:release')"
              @click="searchChildExam(scope.$index, scope.row)">配置</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :paginations="paginations"></pagination>
    </el-card>
    <el-dialog  fullscreen :title="dialogTitle" :visible.sync="dialogFormVisible" width="90%">
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>考核周期基本信息</span>
        </div>
        <el-form ref="addBaseData"  :rules="rules" :model="addBaseData" label-width="140px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="考核周期名称" prop="assessmenYear">
                <el-input v-model="addBaseData.assessmenYear"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="考核周期起始时间" prop="assessmenBeginTime">
                <el-date-picker
                  v-model="SeTime"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="-"
                  @change="getDates"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card padding" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>考核指标信息</span>
          <span style="margin-left: 20px">总权重: <em class="num" style="color:#409eff">{{this.memberAssessmentScore}}</em> -----当前考核指标权重：<em class="num" :style="Num>this.memberAssessmentScore ? 'color:red' : 'color:#409eff'">{{Num}}</em></span>
          <div class="btn-box">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit-outline"
              @click="addSearchCondition" style="margin-right:20px">新增指标</el-button>
            <el-button  type="primary"  icon="el-icon-plus" @click="submitForm" :disabled="disabled">保 存</el-button>
          </div>
        </div>
        <el-row  class="addRow"  :gutter="20">
          <el-col :span="4"  align="center">
              <span style="color:#f56c6c">*</span>指标类型
          </el-col>
          <el-col :span="10"  align="center">
              <span style="color:#f56c6c">*</span>考核指标
          </el-col>
          <el-col :span="2"  align="center">
            <span style="color:#f56c6c">*</span>指标权重
          </el-col>
          <el-col :span="2"  align="center">
            <span style="color:#f56c6c">*</span>排序编号
          </el-col>
          <el-col :span="4" align="center">
              指标描述
          </el-col>
        </el-row>
        <el-row  v-for="(item,index) in liList" :key="item.id" class="addRow"  :gutter="20">
          <el-form  :rules="rules"  :model="liList[index]" :ref="liList[index]">
            <el-col :span="4">
              <el-form-item prop="indexTypeKey">
                <el-select v-model="liList[index].indexTypeKey" placeholder="请选择指标类型" class="tree-select">
                  <el-option
                    v-for="item in dyIndexTypeList"
                    :key="item.indexTypeKey"
                    :label="item.typeName"
                    :value="item.indexTypeKey">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item  prop="dyIndexName" >
                <el-input type="textarea" v-model="liList[index].dyIndexName" placeholder="请输入考核指标名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2">
              <el-form-item  prop="weights">
                <el-input v-model="liList[index].weights" @keyup.native="getNum($event)"  placeholder="请输入权重分值"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2">
              <el-form-item  prop="sortNumber">
                <el-input v-model="liList[index].sortNumber" placeholder="请输入排序序号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="indexDescription">
                <el-input v-model="liList[index].indexDescription" placeholder="指标描述"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="2" center>
              <el-button
                size="mini"
                icon="el-icon-delete"
                type="danger"
                @click="removeSearchCondition(index)" class="delBtns">删除</el-button>
            </el-col>
          </el-form>
          </el-row>
      </el-card>
    </el-dialog>
    <el-dialog  fullscreen :title="dialogTitle" :visible.sync="detailVisible" width="90%">
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>考核周期基本信息</span>
        </div>
        <el-form ref="addBaseData"  :rules="rules" :model="addBaseData" label-width="140px" class="detailStyle">
          <el-row>
            <el-col :span="12">
              <span class="labelSpan">
                考核周期名称:
              </span>
              <span class="valueSpan">{{addBaseData.assessmenYear}}</span>
            </el-col>
            <el-col :span="12">
              <span class="labelSpan">考核周期起始时间: </span>
              <span class="valueSpan">{{addBaseData.assessmenBeginTime}} -- {{addBaseData.assessmenEndTime}}</span>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>考核指标信息</span>
          <span style="margin-left: 20px">考核指标总分值：<em class="num" :style="Num>100 ? 'color:red' : 'color:#409eff'">{{Num}}</em></span>
        </div>
        <el-table
          :data="detailDatas"
          border
          max-height="450"
          ref="tableData"
          style="width: 100%;margin-bottom:1%;"
          >
          <el-table-column
            label="序号"
            width="60">
            <template slot-scope="scope">
                {{ scope.row.sortNumber }}
            </template>
          </el-table-column>
          <el-table-column
            label="指标类型"
            width="180">
            <template slot-scope="scope">
              <el-select v-model="scope.row.indexTypeKey" disabled placeholder="请选择指标类型" class="tree-select">
                <el-option
                  v-for="item in dyIndexTypeList"
                  :key="item.indexTypeKey"
                  :label="item.typeName"
                  :value="item.indexTypeKey">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            label="考核指标名称"
          >
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.dyIndexName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="权重"
          >
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.weights }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="指标描述"
          >
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.indexDescription }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </el-dialog>
    <el-dialog  fullscreen :title="dialogTitle" :visible.sync="addChildVisible" width="90%">
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>主考核周期详情</span>
        </div>
        <el-form ref="ChildExam" :model="ChildExam" label-width="140px" class="detailStyle">
          <el-row>
            <el-col :span="12">
              <span class="labelSpan">
                考核周期名称:
              </span>
              <span class="valueSpan">{{ChildExam.assessmenYear}}</span>
            </el-col>
            <el-col :span="12">
              <span class="labelSpan">考核周期起始时间: </span>
              <span class="valueSpan">{{ChildExam.assessmenBeginTime}} -- {{ChildExam.assessmenEndTime}}</span>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>新增子考核周期</span>
        </div>
        <el-form ref="addChildExam"  :rules="rules" :model="addChildExam" label-width="140px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="考核子周期名称" prop="quarterAssessmenName">
                <el-input v-model="addChildExam.quarterAssessmenName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="考核周期起始时间" prop="assessmenBeginTime">
                <el-date-picker
                  v-model="childTime"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="-"
                  @change="getDateOther"
                  start-placeholder="开始日期"
                  :picker-options="pickerOptions0"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="排序编号" prop="sortNumber">
                <el-input v-model="addChildExam.sortNumber"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item>
                <el-button type="primary" icon="el-icon-plus" @click="addChild('addChildExam')">保存</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card class="box-card" style="margin-bottom:1%;">
        <div slot="header" class="clearfix">
          <span>子考核信息</span>
        </div>
        <el-table
          :data="childExamList"
          border
          max-height="450"
          ref="tableData"
          style="width: 100%;margin-bottom:1%;"
          >
          <el-table-column
            label="序号"
            width="180">
            <template slot-scope="scope">
                {{ scope.row.sortNumber }}
            </template>
          </el-table-column>
          <el-table-column
            label="子考核名称"
            width="180">
            <template slot-scope="scope">
              <span style="margin-left: 10px">{{ scope.row.quarterAssessmenName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="开始时间"
          >
            <template slot-scope="scope">
              <i class="el-icon-time"></i>
              <span style="margin-left: 10px">{{ scope.row.assessmenBeginTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="结束时间"
          >
            <template slot-scope="scope">
              <i class="el-icon-time"></i>
              <span style="margin-left: 10px">{{ scope.row.assessmenEndTime }}</span>
            </template>
          </el-table-column>
           <el-table-column fixed="right" label="操作" width="100px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              icon="el-icon-delete"
              type="danger"
              @click="deleteChild(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
        </el-table>
      </el-card>
    </el-dialog>
  </div>
</template>
<script>
import Loading from '@/components/loading/loading'
import pagination from '@/components/pagination/index'
import { getExamCircle, addCircleSearch, savsBranchCircle, detailBranchCircle, deleteExamCircle, pushBranchCircle, searchChildCircle, saveChildCircle, deleteChildCircle } from '@/api/partyMember/partyMemberCircle'
import { isvalidNumber, isvalidRequire, isvalidSpecial } from '@/utils/validate'
// 非空
var validateRequire = (rule, value, callback) => {
  if (!isvalidRequire(value)) {
    callback(new Error('请输入必填项'))
  } else {
    callback()
  }
}
// 特殊字符
var validSpecial = (rule, value, callback) => {
  if (!isvalidSpecial(value)) {
    callback(new Error('数据不能包含特殊字符'))
  } else {
    callback()
  }
}
// 数字验证
var validNumber = (rule, value, callback) => {
  if (!isvalidNumber(value)) {
    callback(new Error('只能输入大于0的数字'))
  } else {
    callback()
  }
}
export default {
  components: {
    Loading,
    pagination
  },
  data() {
    this.permissionHandle = this.$permissionHandle
    return {
      pickerOptions0: {
        disabledDate: (time) => {
          return time.getTime() < new Date(this.SeTime[0]).getTime() - 3600 * 1000 * 24 || time.getTime() >= new Date(this.SeTime[1]).getTime()
        }
      },
      paginations: {
        totalNum: 0,
        currentPage: 1,
        pageSize: 10
      },
      searchData: {
        assessmenYear: '',
        pageSize: '10',
        pageNum: '1'
      },
      loading: false,
      dialogTitle: '',
      tableData: [],
      dialogFormVisible: false, // 新增弹出框状态
      detailVisible: false,
      addChildVisible: false,
      deleteDepArry: [],
      detailD: {
        cycleAssessmenKey: ''
      },
      // 列表所选数据集合
      multipleSelection: [],
      SeTime: [],
      addBaseData: {
        cycleAssessmenKey: '',
        assessmenYear: '',
        assessmenBeginTime: '',
        assessmenEndTime: '',
        data: {
          indexHistoryArray: []
        }
      },
      ifDisabled: false,
      addCircleSearchData: [],
      dyIndexTypeList: [],
      dyIndexHistoryList: [],
      liList: [],
      rules: {
        quarterAssessmenName: [
          { required: true, message: '请输入子考核名称' },
          { message: '数据不能包含特殊字符', validator: validateRequire }
        ],
        assessmenYear: [
          { required: true, message: '请输入考核周期名称' },
          { message: '数据不能包含特殊字符', validator: validateRequire }
        ],
        assessmenBeginTime: [
          { required: true, message: '请选择考核起止时间', trigger: 'blur' }
        ],
        indexTypeKey: [
          { required: true, message: '请选择指标类型', trigger: 'change' }
        ],
        dyIndexName: [
          { required: true, message: '请输入考核指标名称' },
          { message: '数据不能包含特殊字符', validator: validateRequire }
        ],
        sortNumber: [
          { required: true, message: '请输入考核排序序号' },
          { type: 'number', validator: validNumber }
        ],
        weights: [
          { required: true, message: '请输入考核权重分值' },
          { type: 'number', validator: validNumber }
        ],
        indexDescription: [
          { message: '数据不能包含特殊字符', validator: validSpecial }
        ]
      },
      memberAssessmentScore: 0,
      validateFlag: false,
      changeFlag: false,
      detailDatas: [],
      Num: 0,
      disabled: false,
      $refs: [],
      childTime: [],
      addChildExam: {
        cycleAssessmenKey: '',
        quarterAssessmenName: '',
        assessmenBeginTime: '',
        assessmenEndTime: '',
        sortNumber: ''
      },
      ChildExam: {
        assessmenYear: '',
        assessmenBeginTime: '',
        assessmenEndTime: ''
      },
      childExamList: [],
      deletaExam: []
    }
  },
  created() {
    this.getList()
    this.getNum()
  },
  watch: {
    dialogFormVisible: function() {
      if (!this.dialogFormVisible) {
        this.addBaseData = {
          cycleAssessmenKey: '',
          assessmenYear: '',
          assessmenBeginTime: '',
          assessmenEndTime: '',
          data: {
            indexHistoryArray: []
          }
        }
        this.SeTime = []
        this.resetForm()
      }
    },
    detailVisible: function() {
      if (!this.dialogFormVisible) {
        this.addBaseData = {
          cycleAssessmenKey: '',
          assessmenYear: '',
          assessmenBeginTime: '',
          assessmenEndTime: '',
          data: {
            indexHistoryArray: []
          }
        }
        this.SeTime = []
        this.resetForm()
      }
    }
  },
  methods: {
    getDates(val) {
      if (val !== null) {
        this.addBaseData.assessmenBeginTime = this.SeTime[0]
        this.addBaseData.assessmenEndTime = this.SeTime[1]
      } else {
        this.addBaseData.assessmenBeginTime = ''
        this.addBaseData.assessmenEndTime = ''
      }
    },
    getDateOther(val) {
      if (val !== null) {
        this.addChildExam.assessmenBeginTime = this.childTime[0]
        this.addChildExam.assessmenEndTime = this.childTime[1]
      } else {
        this.addChildExam.assessmenBeginTime = ''
        this.addChildExam.assessmenEndTime = ''
      }
    },
    resetSearch() {
      this.searchData.assessmenYear = ''
      this.getList()
    },
    getNum(e) {
      this.Num = 0
      for (var index in this.liList) {
        this.Num += Number(this.liList[index].weights)
      }
      if (this.Num > this.memberAssessmentScore) {
        this.$message({
          showClose: true,
          message: '考核总权重不能超过' + this.memberAssessmentScore + '分，否则数据保存错误',
          type: 'warning'
        })
      }

      if (this.Num > this.memberAssessmentScore) {
        this.disabled = true
      } else {
        this.disabled = false
      }
    },
    blurSearch() {
      this.getList()
    },
    openDialog() {
      this.Num = 0
      this.dialogFormVisible = true
      this.dialogTitle = '新增考核周期'
      this.searchData.assessmenYear = ''
      this.getCircleDetail()
    },
    // 新增获取数据
    getCircleDetail() {
      addCircleSearch(this.detailD).then(response => {
        // console.log(this.SearchDep)
        this.liList = []
        this.addBaseData.data.indexHistoryArray = []
        this.memberAssessmentScore = response.data.memberAssessmentScore
        this.dyIndexTypeList = response.data.dyIndexTypeList
        this.releaseState = response.data.releaseState
        this.dyIndexHistoryList = response.data.dyIndexHistoryList
        this.dyIndexHistoryList.forEach(element => {
          this.liList.push({
            cycleAssessmenKey: element.cycleAssessmenKey,
            indexTypeKey: element.indexTypeKey,
            dyIndexName: element.dyIndexName,
            sortNumber: parseInt(element.sortNumber),
            weights: parseInt(element.weights),
            indexDescription: element.indexDescription
          })
        })
        this.getNum()
        this.detailD.cycleAssessmenKey = ''
        this.loading = false
      }).catch(error => {
        this.loading = false
        console.log(error)
      })
    },
    // 修改获取详细
    changeCircle() {
      detailBranchCircle(this.detailD).then(response => {
        // console.log(this.SearchDep)
        this.liList = []
        this.memberAssessmentScore = response.data.memberAssessmentScore
        this.addBaseData.data.indexHistoryArray = []
        this.dyIndexHistoryList = []
        this.addBaseData.assessmenYear = response.data.entity.assessmenYear
        this.SeTime = [response.data.entity.assessmenBeginTime, response.data.entity.assessmenEndTime]
        this.addBaseData.assessmenEndTime = response.data.entity.assessmenEndTime
        this.addBaseData.assessmenBeginTime = response.data.entity.assessmenBeginTime
        this.addBaseData.cycleAssessmenKey = response.data.entity.cycleAssessmenKey
        this.dyIndexTypeList = response.data.dyIndexTypeList
        this.releaseState = response.data.releaseState
        this.dyIndexHistoryList = response.data.dyIndexHistoryList
        this.detailDatas = response.data.dyIndexHistoryList
        this.dyIndexHistoryList.forEach(element => {
          this.liList.push({
            cycleAssessmenKey: element.cycleAssessmenKey,
            indexTypeKey: element.indexTypeKey,
            dyIndexName: element.dyIndexName,
            sortNumber: parseInt(element.sortNumber),
            weights: parseInt(element.weights),
            indexDescription: element.indexDescription
          })
        })
        this.detailD.cycleAssessmenKey = ''
        this.getNum()
        this.loading = false
      }).catch(error => {
        this.detailD.cycleAssessmenKey = ''
        this.loading = false
        console.log(error)
      })
    },
    getList() {
      this.searchData.pageNum = 1
      this.getCircleList()
      this.paginations.currentPage = 1
    },
    // 获取周期列表
    getCircleList() {
      this.loading = true
      return new Promise((resolve, reject) => {
        getExamCircle(this.searchData).then(response => {
          // console.log(this.SearchDep)
          this.tableData = response.data.items
          this.paginations.totalNum = parseInt(response.data.itemsTotalCount)
          resolve()
          this.loading = false
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    // 删除
    deleteExam() {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return new Promise((resolve, reject) => {
          deleteExamCircle({ 'cycleAssessmenKey': JSON.stringify(this.deleteDepArry) }).then(response => {
            resolve()
            this.loading = false
            this.getList()
            this.deleteDepArry = []
          }).catch(error => {
            this.loading = false
            this.deleteDepArry = []
            reject(error)
          })
        })
      }).catch(() => {
        this.deleteDepArry = []
        return
      })
    },
    // 保存新增考核周期
    saveCircle() {
      this.liList.forEach(element => {
        this.addBaseData.data.indexHistoryArray.push(element)
      })
      this.loading = true
      this.addBaseData.data = JSON.stringify(this.addBaseData.data)
      savsBranchCircle(this.addBaseData).then(response => {
        // console.log(this.SearchDep)
        this.loading = false
        this.dialogFormVisible = false
        this.getList()
        this.addBaseData.data = {
          indexHistoryArray: []
        }
      }).catch(error => {
        this.addBaseData.data = JSON.parse(this.addBaseData.data)
        this.loading = false
        console.log(error)
      })
    },
    handleEdit(index, row) {
      this.Num = 0
      this.dialogFormVisible = true
      this.dialogTitle = '考核周期修改'
      this.addBaseData.data.indexHistoryArray = []
      this.detailD.cycleAssessmenKey = row.cycleAssessmenKey
      this.changeCircle()
    },
    // 发布
    pushData(index, row) {
      this.detailD.cycleAssessmenKey = row.cycleAssessmenKey
      pushBranchCircle(this.detailD).then(response => {
        this.loading = false
        this.getList()
        this.detailD.cycleAssessmenKey = ''
      }).catch(error => {
        this.loading = false
        this.detailD.cycleAssessmenKey = ''
        console.log(error)
      })
    },
    handleDetail(index, row) {
      this.detailVisible = true
      this.dialogTitle = '考核周期详情'
      this.detailD.cycleAssessmenKey = row.cycleAssessmenKey
      this.changeCircle()
    },

    // 删除事件
    handleDelete(index, row) {
      this.$refs.tableData.clearSelection()
      this.deleteDepArry = []
      this.deleteDepArry.push(row.cycleAssessmenKey)
      this.deleteExam()
    },
    // 改变分页的时候查询数据
    handleSizeChange(val) {
      this.searchData.pageSize = val
      this.getCircleList()
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val
      this.getCircleList()
    },
    // 新增指标
    addSearchCondition() {
      this.liList.unshift({
        cycleAssessmenKey: '',
        indexTypeKey: '',
        dyIndexName: '',
        indexDescription: '',
        sortNumber: '',
        weights: ''
      })
    },
    removeSearchCondition(index) { // 搜索里面的删除搜索项
      this.liList.splice(index, 1)
      this.getNum()
    },
    validateAddForm() {
      console.log(this.$refs[Object()])
      if (this.$refs[Object()] !== undefined) {
        if (this.$refs[Object()].length !== 0) {
          for (const index in this.$refs[Object()]) {
            this.$refs[Object()][index].validate((valid) => {
              if (valid) {
              // this.saveCircle()
                this.validateFlag = true
              } else {
                this.validateFlag = false
              }
            })
            if (!this.validateFlag) {
              break
            }
          }
          if (this.validateFlag) {
            this.saveCircle()
          }
        } else {
          this.saveCircle()
        }
      } else {
        this.saveCircle()
      }
    },
    submitForm() {
      this.addBaseData.data.indexHistoryArray = []
      this.$refs['addBaseData'].validate((valid) => {
        if (valid) {
          this.validateAddForm()
        } else {
          this.validateFlag = false
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm() {
    // this.dialogFormVisible = false
      if (this.$refs[Object()]) {
        this.$refs[Object()].forEach(element => {
          element.resetFields()
        })
      }
      this.$refs['addBaseData'].resetFields()
    },
    searchChildDetail() {
      searchChildCircle(this.detailD).then(response => {
        this.loading = false
        this.childExamList = response.data.quarterCycleList
        this.SeTime = [response.data.dyCycleAssessmen.assessmenBeginTime, response.data.dyCycleAssessmen.assessmenEndTime]
        this.ChildExam.assessmenYear = response.data.dyCycleAssessmen.assessmenYear
        this.ChildExam.assessmenEndTime = response.data.dyCycleAssessmen.assessmenEndTime
        this.ChildExam.assessmenBeginTime = response.data.dyCycleAssessmen.assessmenBeginTime
        this.addChildExam.cycleAssessmenKey = response.data.dyCycleAssessmen.cycleAssessmenKey
      }).catch(error => {
        this.loading = false
        this.detailD.cycleAssessmenKey = ''
        console.log(error)
      })
    },
    searchChildExam(idnex, row) {
      this.addChildVisible = true
      this.dialogTitle = '配置子考核'
      this.detailD.cycleAssessmenKey = row.cycleAssessmenKey
      this.searchChildDetail()
    },
    addChild(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          saveChildCircle(this.addChildExam).then(response => {
            // console.log(this.SearchDep)
            this.loading = false
            this.dialogFormVisible = false
            this.detailD.cycleAssessmenKey = this.addChildExam.cycleAssessmenKey
            this.searchChildDetail()
          }).catch(error => {
            this.loading = false
            console.log(error)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    deleteChild(index, row) {
      this.deletaExam.push(row.quarterCycleKey)
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteChildCircle({ 'quarterCycleKey': JSON.stringify(this.deletaExam) }).then(response => {
          // console.log(this.SearchDep)
          this.loading = false
          this.detailD.cycleAssessmenKey = this.addChildExam.cycleAssessmenKey
          this.searchChildDetail()
        }).catch(error => {
          this.loading = false
          console.log(error)
        })
      }).catch(() => {
        return
      })
    }
  }
}
</script>
<style lang="scss" scoped>
 .tree-select,.el-date-editor{width: 95%;}
 .el-input{width: 95%;}
 .delBtns{position: relative;left:20%;top:5px;}
.num{font-size: 18px;font-style: normal;font-weight: 700;}
.padding .el-card__header div{position: relative;}
  .padding .el-card__header .btn-box{position: absolute;right:0;top:50%;transform: translate(0 ,-50%)}

    
</style>
<style>
</style>


